local duxi = fk.CreateSkill({
    name = "sj6__duxi",
    tags = {Skill.Limited}
  })
  
  Fk:loadTranslationTable{
    ["sj6__duxi"] = "渡袭",
    [":sj6__duxi"] = "<b>限定技</b>，每回合结束时，若你本回合未使用过【杀】且<a href='zhongyangqu_js'>中央区</a>的牌包含四种花色，你可以依次视为使用你技能描述中包含的牌名。",
  
    ["#sj6__duxi"] = "渡袭：你可以依次视为使用你技能中包含的牌名",
    ["@sj6__duxi-turn"] = "渡袭",
  
    ["$sj6__duxi1"] = "今日起兵，渡江攻敌！",
    ["$sj6__duxi2"] = "时机已到，全军出击！",  
  }

--寻找文本的函数
  local function extractBracketContents(text, openBracket, closeBracket)
    local result = {}
    local startPos = 1
    local openPos, closePos
  
    while true do
        openPos = string.find(text, openBracket, startPos)
        if not openPos then break end
  
        closePos = string.find(text, closeBracket, openPos + #openBracket)
        if not closePos then break end
  
        local content = string.sub(text, openPos + #openBracket, closePos - 1)
        table.insert(result, content)
  
        startPos = closePos + #closeBracket
    end
  
    return result
  end

  duxi:addEffect(fk.TurnEnd, {
    prompt = "#sj6__duxi",
    can_trigger = function(self, event, target, player, data)
      return player:hasSkill(duxi.name) and 
      player:usedSkillTimes(duxi.name, Player.HistoryGame) == 0 and
      player:usedCardTimes("slash") == 0 and #player:getTableMark("@sj6__duxi-turn") == 4
    end,
    on_use = function (self, event, target, player, data)
      local room = player.room
      room:delay(800)
      local skills = table.filter(player.player_skills, function(s) return not s:isEquipmentSkill(player) end)
      --过滤装备的技能
      local cardName = {}
      for i, s in ipairs(skills) do
        local n = extractBracketContents(Fk:translate(":"..s.name),"【", "】")
        for j, cn in ipairs(n) do
          table.insert(cardName,cn)
          for _, v in ipairs(Fk.all_card_names) do --翻译表没法从译文转原文，暂时用所有牌堆检索
            if Fk:translate(v) == cn and (Fk:cloneCard(v).type ~= Card.TypeEquip and Fk:cloneCard(v).sub_type ~= Card.SubtypeDelayedTrick) then
              if i > 1 or j > 1 then player:broadcastSkillInvoke(duxi.name) end
              room:askToUseVirtualCard(player,{
                name = v,
                skill_name = duxi.name,
              })
            end
          end
        end
      end
    end,
  })

  duxi:addEffect(fk.AfterCardsMove, {
  can_refresh = function(self, event, target, player, data)
    if player:hasSkill(duxi.name, true) and player:usedSkillTimes(duxi.name, Player.HistoryGame) == 0 then
      for _, move in ipairs(data) do
        if move.toArea == Card.DiscardPile then
          for _, info in ipairs(move.moveInfo) do
            if table.contains(player.room.discard_pile, info.cardId) then
              return true
            end
          end
        end
        for _, info in ipairs(move.moveInfo) do
          if info.fromArea == Card.DiscardPile and not table.contains(player.room.discard_pile, info.cardId) then
            return true
          end
        end
      end
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    local ids = player:getTableMark("sj6__duxi-turn")
    for _, move in ipairs(data) do
      if move.toArea == Card.DiscardPile then
        for _, info in ipairs(move.moveInfo) do
          if table.contains(room.discard_pile, info.cardId) then
            table.insertIfNeed(ids, info.cardId)
          end
        end
      end
      for _, info in ipairs(move.moveInfo) do
        if info.fromArea == Card.DiscardPile and not table.contains(room.discard_pile, info.cardId) then
          table.removeOne(ids, info.cardId)
        end
      end
    end
    room:setPlayerMark(player, "sj6__duxi-turn", ids)
    for _, v in ipairs(player:getTableMark("sj6__duxi-turn")) do--添加花色
      player.room:addTableMarkIfNeed(player, "@sj6__duxi-turn", Fk:getCardById(v):getSuitString(true))
    end
  end,
  })

  return duxi